## java env
export JAVA_HOME=/opt/jdk1.7.0_79
export JRE_HOME=$JAVA_HOME/jre

## restart tomcat
current_dir=$(cd `dirname $0`; pwd)
echo "=== current_dir is:$current_dir"

P_ID=`ps -ef | grep -w "$current_dir" | grep -w "java" | awk '{print $2}'`
if [ "$P_ID" == "" ]; then
    echo "=== $current_dir process not exists or stop success"
else
    echo "=== $current_dir process pid is:$P_ID"
    echo "=== begin stop $current_dir"
    $current_dir/bin/shutdown.sh
	sleep 5
fi

P_ID=`ps -ef | grep -w "$current_dir" | grep -w "java" | awk '{print $2}'`
if [ "$P_ID" != "" ]; then
    echo "=== $current_dir stop failed, process pid is:$P_ID"
    echo "=== begin kill -9 $P_ID"
    kill -9 $P_ID
	sleep 2
fi

rm -rf $current_dir/webapps/*/

echo "=== begin start $current_dir"
$current_dir/bin/startup.sh

